﻿<!-- 综合监控页面 -->

<div id="map_box" class ="baidu-maps" style="width: 100%;height: 100%"></div>
<!-- 报警设置表单开始 -->
<form  class="layui-form layui-form-pane " action="" id="set_param_form" lay-filter="set_param_form" style="padding: 10px;display: none;">
  <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
    <legend style="font-size: 15px">心率报警</legend>
  </fieldset>
   <div id="heart_rate_slider" class="heart_rate_slider"></div>
   <br>
  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label layui-bg-green">心率低于</label>
      <div class="layui-input-block">
        <input id="heart_low" type="text" name="heart_low"  placeholder="40"  autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label layui-bg-green">心率高于</label>
      <div class="layui-input-block">
        <input id="heart_hight" type="text" name="heart_hight" lay-verify="required" autocomplete="off" placeholder="150" class="layui-input">
      </div>
    </div>
  </div>

  <div class="layui-form-item">
    <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
      <legend style="font-size: 15px">血压高压报警</legend>
    </fieldset>
     <div id="h_pres_slider" class="heart_rate_slider"></div>
     <br>
    <div class="layui-inline">
      <label class="layui-form-label layui-bg-green">高压低于</label>
      <div class="layui-input-block">
        <input id="h_pres_low" type="text" name="h_pres_low"  placeholder=""  autocomplete="off" class="layui-input">
      </div>
    </div>
    <div class="layui-inline">
      <label class="layui-form-label layui-bg-green">高压高于</label>
      <div class="layui-input-block">
        <input id="h_pres_hight" type="text" name="h_pres_hight" lay-verify="required" autocomplete="off" placeholder="" class="layui-input">
      </div>
    </div>
  </div>

  <div class="layui-form-item">
      <fieldset class="layui-elem-field layui-field-title" style="margin-top: 10px;">
        <legend style="font-size: 15px">血压低压报警</legend>
      </fieldset>
       <div id="l_pres_slider" class="heart_rate_slider"></div>
       <br>
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green">低压低于</label>
        <div class="layui-input-block">
          <input id="l_pres_low" type="text" name="l_pres_low"  placeholder=""  autocomplete="off" class="layui-input">
        </div>
      </div>
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green">低压高于</label>
        <div class="layui-input-block">
          <input id="l_pres_hight" type="text" name="l_pres_hight" lay-verify="required" autocomplete="off" placeholder="" class="layui-input">
        </div>
      </div>
  </div>

  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label layui-bg-green">温度报警</label>
      <div class="layui-input-inline">
        <input type="text" name="tem_alarm"  placeholder="C°"  autocomplete="off" class="layui-input">
      </div>
      <div class="layui-form-mid layui-word-aux">C°</div>
    </div>
  </div>

  <div class="layui-form-item" >
    <div class="layui-inline">
      <label class="layui-form-label layui-bg-green">停留报警</label>
      <div class="layui-input-inline">
        <input type="text" name="stop_rate"  placeholder="分钟"  autocomplete="off" class="layui-input">
      </div>
      <div class="layui-form-mid layui-word-aux">分钟</div>
    </div>
    <div class="layui-inline" style="display: none;">
      <label class="layui-form-label layui-bg-green">设备编号</label>
      <div class="layui-input-block">
        <input id="alarm_set_device" type="text" name="alarm_set_device"  placeholder="分钟"  autocomplete="off" class="layui-input">
      </div>
    </div>
  </div>

  <div class="layui-form-item">
    <button class="layui-btn" lay-submit="" lay-filter="data_handle_btn" id="set_param_submit" style="display: none;"></button>
  </div>
</form>

<!-- 报警设置表单结束 -->


<!-- 命令下发弹窗开始 -->
<!-- 命令下发表格的执行按钮 -->
<script type="text/html" id="command_table_bar">
    <a class="layui-btn layui-btn-xs" lay-event="excue_command">执行</a>
</script>
<form  class="layui-form layui-form-pane " action="" id="command_form" lay-filter="command_form" style="padding: 10px;display: none;">
  <table class="layui-table" id="command_down_table"  lay-filter="command_table_filter" style="padding: 0px 0px 0px 0px;margin: 0px 0px 0px 0px">
  </table>
</form>
<!-- 命令下发弹窗结束 -->

<!-- 硬件参数设置开始 -->
<form  class="layui-form layui-form-pane " action="" id="param_set_form" lay-filter="param_set_form" style="padding: 10px;display: none;">
  <input type="" name="" id="set_device_id" style="display: none;">
  <div class="layui-col-lg6">
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green">回传间隔</label>
        <div class="layui-input-inline">
          <input id="send_rate" type="text" name="send_rate"  placeholder="秒" value="30"  autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">秒</div>
        <a class="layui-btn" onclick="device_set('send_rate',$('#set_device_id').val(),$('#send_rate').val())"><i class="layui-icon layui-icon-set" style="font-size: 12px"> 提交</i></a>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green">健康监测频率</label>
        <div class="layui-input-inline">
          <input id="health_rate" type="text" name="health_rate"  placeholder="秒" value="300"  autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">秒</div>
        <a class="layui-btn" onclick="device_set('health_rate',$('#set_device_id').val(),$('#health_rate').val())"><i class="layui-icon layui-icon-set" style="font-size: 12px"> 提交</i></a>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green">中心号码</label>
        <div class="layui-input-inline">
          <input id="center_num_set" type="text" name="center_num_set"  placeholder="主要电话号码"   autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">—</div>
        <a class="layui-btn" onclick="device_set('center_num_set',$('#set_device_id').val(),$('#center_num_set').val())"><i class="layui-icon layui-icon-set" style="font-size: 12px"> 提交</i></a>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green">SOS号码</label>
        <div class="layui-input-inline">
          <input  id="sos_set_value" type="text" name="sos"  placeholder="SOS1,SOS2,SOS3" autocomplete="off" class="layui-input"> 
        </div>
        <div class="layui-form-mid layui-word-aux">—</div>
        <a class="layui-btn" onclick="sos_set()"><i class="layui-icon layui-icon-set" style="font-size: 12px"> 详情</i></a>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green">工作模式</label>
        <div class="layui-input-inline">
          <select id="work_model" name="work_model"  >
            <option value="2">省电</option>
            <option value="1" selected="">普通</option>
            <option value="3">紧急</option>
          </select>
        </div>
        <div class="layui-form-mid layui-word-aux">—</div>
        <a class="layui-btn" onclick="device_set('work_model',$('#set_device_id').val(),$('#work_model').val())"><i class="layui-icon layui-icon-set" style="font-size: 12px"> 提交</i></a>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green">计步时间</label>
        <div class="layui-input-inline">
          <input id="walk_time_set" type="text" name="walk_time_set"  placeholder="采集运动步数时间段" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">—</div>
        <a class="layui-btn" onclick="device_set('walk_time_set',$('#set_device_id').val(),$('#walk_time_set').val())"><i class="layui-icon layui-icon-set" style="font-size: 12px"> 提交</i></a>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green">禁用时间</label>
        <div class="layui-input-inline">
          <input id="silence_time_set" type="text" name="silence_time_set"  placeholder="禁止接收来电时间段" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">—</div>
        <a class="layui-btn" onclick="device_set('silence_time_set',$('#set_device_id').val(),$('#silence_time_set').val())"><i class="layui-icon layui-icon-set" style="font-size: 12px"> 提交</i></a>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green">翻滚检测</label>
        <div class="layui-input-inline">
          <input id="sleep_time" type="text" name="sleep_time"  placeholder="检测设备翻转时间段" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">—</div>
        <a class="layui-btn" onclick="device_set('sleep_time',$('#set_device_id').val(),$('#sleep_time').val())"><i class="layui-icon layui-icon-set" style="font-size: 12px"> 提交</i></a>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green">闹钟设置</label>
        <div class="layui-input-inline">
          <input id="time_remind" type="text" name="time_remind"  placeholder="闹钟设置" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">—</div>
        <a class="layui-btn" onclick="clock_set()"><i class="layui-icon layui-icon-set" style="font-size: 12px"> 详情</i></a>
      </div>
    </div>

  </div>
  <!-- 弹窗另一半 -->
  <div class="layui-col-lg6">
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green" style="width: 120px">SOS短信开关</label>
        <div class="layui-input-inline">
          <input type="checkbox" name="sosmsg_to_phone" lay-skin="switch" lay-filter="dev_func_switch" lay-text="ON|OFF">
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green" style="width: 120px">低电短信报警</label>
        <div class="layui-input-inline">
          <input type="checkbox" name="low_power_msg" lay-skin="switch" lay-filter="dev_func_switch" lay-text="ON|OFF">
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green" style="width: 120px">设备拆除报警</label>
        <div class="layui-input-inline">
          <input type="checkbox" name="dev_remove_alarm" lay-skin="switch" lay-filter="dev_func_switch" lay-text="ON|OFF">
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green" style="width: 120px">设备拆除短信</label>
        <div class="layui-input-inline">
          <input type="checkbox" name="dev_remove_msg" lay-skin="switch" lay-filter="dev_func_switch" lay-text="ON|OFF">
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green" style="width: 120px">计步功能开关</label>
        <div class="layui-input-inline">
          <input type="checkbox"  name="step_cunt_btn" lay-skin="switch" lay-filter="dev_func_switch" lay-text="ON|OFF">
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green" style="width: 120px">摔倒报警开关</label>
        <div class="layui-input-inline">
          <input type="checkbox"  name="fall_down" lay-skin="switch" lay-filter="dev_func_switch" lay-text="ON|OFF">
        </div>
      </div>
    </div>

  </div>
</form>

<!-- 硬件参数设置结束 -->

<!-- SOS设置start -->

<form  class="layui-form layui-form-pane " action="" id="sos_set_form" lay-filter="sos_set_form" style="padding: 10px;display: none;">
  <font color="#BDCADA">设置三个sos号码，号码后面的开关设置该SOS号码是否生效</font> 
  <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green">SOS-1</label>
        <div class="layui-input-inline">
          <input id="sos1" type="phone" name="sos1"  placeholder="SOS1" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">—</div>
       <input type="checkbox"  name="sos1_sw" lay-skin="switch" lay-filter="" lay-text="ON|OFF">
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green">SOS-2</label>
        <div class="layui-input-inline">
          <input id="sos2" type="phone" name="sos2"  placeholder="SOS2" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">—</div>
       <input type="checkbox"  name="sos2_sw" lay-skin="switch" lay-filter="" lay-text="ON|OFF">
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label layui-bg-green">SOS-3</label>
        <div class="layui-input-inline">
          <input id="sos3" type="phone" name="sos3"  placeholder="SOS3" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid layui-word-aux">—</div>
       <input type="checkbox"  name="sos3_sw" lay-skin="switch" lay-filter="" lay-text="ON|OFF">
      </div>
    </div>
  <button id="sos_set_btn" class="layui-btn" lay-submit lay-filter="sos_set_form" style="position: absolute;left: 40%;width: 200px">提交</button>
</form>
<!-- SOS设置end-->

<!-- 闹钟设置start -->

<form  class="layui-form layui-form-pane " action="" id="alarm_clock_form" lay-filter="alarm_clock_form" style="padding: 10px;display: none;">
  <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label layui-bg-green">闹钟-1</label>
      <div class="layui-input-inline" style="width: 120px">
        <input id="clock1" type="phone" name="clock1"  placeholder="" autocomplete="off" class="layui-input alarm_clock">
      </div>
      <div class="layui-input-inline" style="width: 100px">
        <select name="clock1_type" >
          <option value="clock">闹钟</option>
          <option value="take_pill">吃药提醒</option>
          <option value="long_sit_alarm">久坐提醒</option>
          <option value="drink_water">喝水提醒</option>
        </select>
      </div>
      <div class="layui-input-inline" style="width: 100px" >
        <select name="clock1_rate">
          <option value="alarm_one">只响一次</option>
          <option value="alarm_everyday">每天都响</option>
          <option value="customize">自定义</option>
        </select>
      </div>
      <div class="layui-input-inline customize_clock" style="width: 160px;">
        <select name="customize1" xm-select="customize1" xm-select-type="1" xm-select-height="36px">
          <option value="1">星期一</option>
          <option value="2">星期二</option>
          <option value="3">星期三</option>
          <option value="4">星期四</option>
          <option value="5">星期五</option>
          <option value="6">星期六</option>
          <option value="7">星期日</option>
        </select>
      </div>
      <div class="layui-form-mid layui-word-aux">—</div>
     <input type="checkbox" name="clock1_sw" lay-skin="switch" lay-filter="" lay-text="ON|OFF">
    </div>
  </div>
    <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label layui-bg-green">闹钟-2</label>
      <div class="layui-input-inline" style="width: 120px">
        <input id="clock2" type="phone" name="clock2"  placeholder="" autocomplete="off" class="layui-input alarm_clock">
      </div>
      <div class="layui-input-inline" style="width: 100px">
        <select name="clock2_type" >
          <option value="clock">闹钟</option>
          <option value="take_pill">吃药提醒</option>
          <option value="long_sit_alarm">久坐提醒</option>
          <option value="drink_water">喝水提醒</option>
        </select>
      </div>
      <div class="layui-input-inline" style="width: 100px" >
        <select name="clock2_rate">
          <option value="alarm_one">只响一次</option>
          <option value="alarm_everyday">每天都响</option>
          <option value="customize">自定义</option>
        </select>
      </div>
      <div class="layui-input-inline customize_clock" style="width: 160px;">
        <select name="customize2"  xm-select="customize2" xm-select-type="1" xm-select-height="36px">
          <option value="1">星期一</option>
          <option value="2">星期二</option>
          <option value="3">星期三</option>
          <option value="4">星期四</option>
          <option value="5">星期五</option>
          <option value="6">星期六</option>
          <option value="7">星期日</option>
        </select>
      </div>
      <div class="layui-form-mid layui-word-aux">—</div>
     <input type="checkbox" name="clock2_sw" lay-skin="switch" lay-filter="" lay-text="ON|OFF">
    </div>
  </div>
    <div class="layui-form-item">
    <div class="layui-inline">
      <label class="layui-form-label layui-bg-green">闹钟-3</label>
      <div class="layui-input-inline" style="width: 120px">
        <input id="clock3" type="phone" name="clock3"  placeholder="" autocomplete="off" class="layui-input alarm_clock">
      </div>
      <div class="layui-input-inline" style="width: 100px">
        <select name="clock3_type" >
          <option value="clock">闹钟</option>
          <option value="take_pill">吃药提醒</option>
          <option value="long_sit_alarm">久坐提醒</option>
          <option value="drink_water">喝水提醒</option>
        </select>
      </div>
      <div class="layui-input-inline" style="width: 100px" >
        <select name="clock3_rate">
          <option value="alarm_one">只响一次</option>
          <option value="alarm_everyday">每天都响</option>
          <option value="customize">自定义</option>
        </select>
      </div>
      <div class="layui-input-inline customize_clock" style="width: 160px;">
        <select name="customize3"  xm-select="customize3" xm-select-type="1" xm-select-height="36px">
          <option value="1">星期一</option>
          <option value="2">星期二</option>
          <option value="3">星期三</option>
          <option value="4">星期四</option>
          <option value="5">星期五</option>
          <option value="6">星期六</option>
          <option value="7">星期日</option>
        </select>
      </div>
      <div class="layui-form-mid layui-word-aux">—</div>
     <input type="checkbox" name="clock3_sw" lay-skin="switch" lay-filter="" lay-text="ON|OFF">
    </div>
  </div>
  <button id="colck_set_btn" class="layui-btn" lay-submit lay-filter="alarm_clock_form" style="position: absolute;left: 40%;width: 200px">提交</button>
</form>
<!-- 闹钟设置end-->

<!-- 手机用户绑定设备开始 -->
<form  class="layui-form layui-form-pane " action="" id="bind_dev_phoneuser" lay-filter="bind_dev_phoneuser" style="padding: 10px;display: none;">
  <div class="layui-form-item" style="color: white;font-size: 16px">
    <div class="layui-inline">
      <label class="layui-form-label layui-bg-green">设备ID</label>
      <div class="layui-input-inline">
        <input type="text" name="device_id" lay-verify="required" autocomplete="off" placeholder="设备ID" class="layui-input">
      </div>
    </div>
  </div>
   <div class="layui-form-item" style="color: white;font-size: 16px">
    <div class="layui-inline">
      <label class="layui-form-label layui-bg-green">授权码</label>
      <div class="layui-input-inline">
        <input type="text" name="auth_id" lay-verify="required"  placeholder="授权码"  autocomplete="off" class="layui-input">
      </div>
  </div>
  <button id="submit_btn" lay-submit lay-filter="bind_dev_phoneuser" style="display: none;">提交</button>
</form>
<!-- 手机用户绑定设备结束 -->
<!-- 百度地图的相关调用，定位打点，地址解析等 -->
<script type="text/javascript" src="/static/bd_map.js"></script>

<script type="text/javascript">

// ------侧边栏内容处理start--------//
// $('#side2').empty()
// $('#side2').attr('class','empty')
// $('.empty').hide()
// $('#side1').attr('class','layui-side')
// $('.layui-side').show()
// ------侧边栏内容处理end--------//

// ------手机注册用户绑定设备功能开始--------//
// console.log(character['bind_dev'],user_permi)
table.render()
form.render();


var show_bind_dev_form=function(){
  layer.open({
    type: 1
    ,title:'绑定设备'
    ,area:['400px','240px']
    ,offset:'60px'  
    ,id: 'register_data' 
    ,content:$('#bind_dev_phoneuser')
    ,btn: ['提交','关闭']
    ,shade: 0 //不显示遮罩
    ,btn1: function(){
      $('#submit_btn').click()
      
    }
    ,btn2: function(){
      layer.closeAll();
    }
  }); 
}

form.on('submit(bind_dev_phoneuser)',function(obj){
  // console.log(obj.field)
  layer.closeAll()
  var param_data=obj.field
  $.ajax({
    type: 'POST',
    data:param_data,
    url:'/dynamic/?what=phone_user_bind_dev',
    async:true,
    dataType: 'json',
    success: function(data) {
      // console.log(JSON.stringify(data))
      if(data.code==1000){
        layer.msg('绑定设备成功')
        device_list_table(data.data)
      }else{
        alert(data.error)
      }
    },
  });
  return false
})

if(user_permi=='phone_user' && character['bind_dev']==null){
  show_bind_dev_form()
}
// ------手机注册用户绑定设备功能结束--------//




// 监听设备列表点击
// 存储被点击的设备对象的本页面全局变量
var checkDiv={};
table.on('row(dev_list_show)', function(obj){
  click_dev_id(obj)
  layer.closeAll()

});

// 页面数据刷新，局部刷新
var refresh_page=function(){

  for(var i=0;i<device.length;i++){
    if(device[i]['device_id'] in checkDiv){
      device[i]["LAY_CHECKED"]=true
    }
  }
  device_list_table(device)

  setTimeout(function(){
    refresh_page();
  },param_refresh_time_control)
}

refresh_page();

// -----点击设备链表，勾选功能--------//

var click_dev_id=function(obj){//选中行同步选中复选按钮
  var tr = obj.tr;
  var div = tr.find("div.layui-unselect");
  //checkDiv为定义的属性用来缓存当前点击的行是否选中状态，未选择的选中，选中的取消选中，并进行相应的地图打点处理
  // console.log(obj.data.device_id)

  if(!checkDiv[obj.data['device_id']]) {
    chosed_dev=obj.data
    checkDiv[obj.data['device_id']] = obj;
    div.addClass("layui-form-checked");
    add_device_marker_bdmap(obj.data)
  } else {
    div.removeClass("layui-form-checked");
    delete checkDiv[obj.data['device_id']];
    remove_marker_bdmap(obj.data['device_id'])
    chosed_dev={'device_id':'default'}

  }
}



// 报警参数功能js部分开始
// 监听报警参数设置
var set_param=function(device_id,status){
    // console.log(chosed_dev)
    document.getElementById("set_param_form").reset();
    // 参数title字典
    var person_param={'alarm_set_device':device_id};
    // 获取设备报警参数设置信息，并赋值给弹窗

    var param_set=chosed_dev['param_set']
    if(param_set.length!=0){
      var heart_set=param_set['heart_set']
      var blood_set=param_set['blood_set']
      var stop_rate=param_set['stop_rate']
      var tem_alarm=param_set['tem_alarm']
      // console.log(blood_set,heart_set)
      if(heart_set!='0' && heart_set!=null){
        // heart_set=eval('('+heart_set+')')
        person_param['heart_low']=heart_set['heart_low']
        person_param['heart_hight']=heart_set['heart_hight']
        // 给滑块赋值
        heart_rate_slider.setValue(eval(heart_set['heart_low']),0)
        heart_rate_slider.setValue(eval(heart_set['heart_hight']),1)
      }
      if(blood_set!='0' && blood_set!=null){
        // blood_set=eval('('+blood_set+')')
        person_param['l_pres_low']=blood_set['l_pres_low']
        person_param['l_pres_hight']=blood_set['l_pres_hight']
        person_param['h_pres_low']=blood_set['h_pres_low']
        person_param['h_pres_hight']=blood_set['h_pres_hight']
        // 低压报警滑块赋值
        l_pres_slider.setValue(eval(blood_set['l_pres_low']),0)
        l_pres_slider.setValue(eval(blood_set['l_pres_hight']),1)
        // 高压报警滑块赋值
        h_pres_slider.setValue(eval(blood_set['h_pres_low']),0)
        h_pres_slider.setValue(eval(blood_set['h_pres_hight']),1)
      }
      if(stop_rate!='0' && stop_rate!=null){
        // stop_rate=eval('('+stop_rate+')')
        person_param['stop_rate']=stop_rate['stop_rate']
        // console.log(typeof(stop_rate))
      }
      if(tem_alarm!='0' && tem_alarm!=null){
        // stop_rate=eval('('+tem_alarm+')')
        person_param['tem_alarm']=tem_alarm['tem_alarm']
        // console.log(typeof(stop_rate))
      }
    }

    // 把设备之前的参数设置赋值给form
    form.val("set_param_form",person_param)
    
    layer.open({
        type: 1
        ,title:'报警参数设置: '+device_id
        ,area:['700px','600px']
        ,offset:'60px'  
        ,id: 'add_data' //防止重复弹出
        ,content:$('#set_param_form')
        ,btn: ['提交','关闭']
        ,shade: 0 //不显示遮罩
        ,btn1: function(){
            console.log('ok')
            $('#set_param_submit').click();
        }
        ,btn2: function(){
          layer.closeAll();
        }
      });
};
// 报警参数设置上传后台
form.on('submit(data_handle_btn)', function (data) {
  if(chosed_dev.on_off_line!=='online'){
    layer.msg('设备离线，无法执行该指令')
    return false
  }
    var row_data=data.field;
    var alarm_set_data={};
    alarm_set_data['heart_set']={'heart_hight':row_data['heart_hight'],'heart_low':row_data['heart_low']}
    alarm_set_data['blood_set']={'l_pres_low':row_data['l_pres_low'],'l_pres_hight':row_data['l_pres_hight'],
                                    'h_pres_low':row_data['h_pres_low'],'h_pres_hight':row_data['h_pres_hight']}
    alarm_set_data['stop_rate']={'stop_rate':row_data['stop_rate']}
    alarm_set_data['tem_alarm']={'tem_alarm':row_data['tem_alarm']}
    alarm_set_data['device_id']=row_data['alarm_set_device']
    alarm_set_data = JSON.stringify(alarm_set_data);
    // console.log(alarm_set_data)
    $.ajax({
        type: 'POST',
        data:{alarm_set_data},
        url:"/dynamic/?what=alarm_set",
        async:true,
        dataType: 'json',
        success: function(data) {
          // console.log(data)
          layer.closeAll();
          layer.msg('设置成功')
          
        },
    });
    return false;
});

// 心率报警参数选择框渲染
//开启范围选择
var heart_rate_slider=slider.render({
  elem: '#heart_rate_slider'
  ,max:200
  ,value: [40,150] //初始值
  ,range: true //范围选择

  ,change: function(vals){
    $('#heart_low').val(vals[0]);
    $('#heart_hight').val(vals[1]);
  }
});

// 血压高压报警参数选择框渲染
//开启范围选择
var h_pres_slider=slider.render({
  elem: '#h_pres_slider'
  ,max:200
  ,value: [40,150] //初始值
  ,range: true //范围选择

  ,change: function(vals){
    $('#h_pres_low').val(vals[0]);
    $('#h_pres_hight').val(vals[1]);
  }
});

// 血压低压报警参数选择框渲染
//开启范围选择
var l_pres_slider=slider.render({
  elem: '#l_pres_slider'
  ,max:200
  ,value: [40,150] //初始值
  ,range: true //范围选择

  ,change: function(vals){
    $('#l_pres_low').val(vals[0]);
    $('#l_pres_hight').val(vals[1]);
  }
});
// 报警参数功能js部分结束

// ------命令下发功能js部分开始-------//
 // 监听命令下发弹窗
var command_dict={'call_now':'实时点名','factory_set':'恢复出厂设置','verson_detail':'查询版本信息','dev_reset':'远程重启','turn_off_dev':'远程关机',
                  'find_dev':'设备寻找','monitor':'监听','photograph':'远程拍照','health_detect':'健康检测'}

var command_modal=function(device_id,status){
  // 重新组装可以加载到表格的命令数据格式
  // console.log(device_id)
    var command_detail=[]
    for(k in command_dict){
      var comm_value={};
      comm_value['command_style']=k
      comm_value['command_name']=command_dict[k]
      comm_value['device_id']=device_id
      command_detail.push(comm_value)

    }
   

    layer.open({
        type: 1
        ,title:'命令下发: '+device_id
        ,area:'300px'
        ,offset:'60px'  
        ,id: 'command_data' //防止重复弹出
        ,content:$('#command_form')
        ,btn: '关闭'
        ,shade: 0 //不显示遮罩
        ,success:function(layero,index){
            table.render({
            elem: '#command_down_table',
            data: command_detail,
            id:'command_down_table',
            skin:'nob',
            size:'sm',
            cols: [[
                {field: 'device_id', title: '设备ID',hide:true},
                {field: 'command_name',width:120, title: '名称',sort:true},
                {field: 'command_style', title: '命令格式',hide:true},
                {title: '操作',templet: '#command_table_bar', fixed: "right", align: "center"}
            ]],
            page: false
          });
        }
        ,btn1: function(){
          layer.closeAll();
        }
      });

};


//命令下发到后台进行处理
table.on('tool(command_table_filter)', function (obj) {
  if(chosed_dev.on_off_line!=='online'){
    layer.msg('设备离线，无法执行该指令')
    return false
  }
  var comm_result = obj.data;
  var param_data={'device_id':comm_result.device_id,'set_command':comm_result.command_style,'set_value':'1','send_time':$('#get_current_time').text(),'port':chosed_dev.dynamic.receive_port}
  param_data=JSON.stringify(param_data)
  // console.log(param_data)
  $.ajax({
    type: 'POST',
    data:{param_data},
    url:"/dynamic/?what="+"order_dowm",
    async:true,
    dataType: 'json',
    success: function(data) {
      if(data=='set_param,ok!'){
        layer.msg('操作成功')
      }else{
         layer.msg('操作失败')
      }
      // console.log(data)
    },

  });
});
// ------命令下发功能end-------//

// 设备参数设置功能js部分开始
// var param_dict0={'send_rate':'回传频率','health_rate':'健康检测频率','center_num_set':'设置中心号码','phone_call':'拨打电话','sos1':'紧急呼叫号码1',
//         'sos2':'紧急呼叫号码2','sos3':'紧急呼叫号码3','ip_port':'服务器IP端口设置','time_language':'设备语言选择','sosmsg_to_phone':'SOS短信开关',
//         'low_power_msg':'低电量报警短信开关','dev_remove_alarm':'设备拆除报警开关','dev_remove_msg':'设备拆除短信开关','step_cunt_btn':'计步功能开关',
//         'work_model':'工作模式'}
// var param_dict1={'fall_down':'摔倒报警开关','walk_time_set':'计步时间设置','silence_time_set':'禁用时间设置','time_remind':'闹钟设置',
//                   'sleep_time':'设备翻滚检测时间设置','long_sit_alarm':'久坐提醒','take_medicine':'喝药提醒','drink_water':'喝水提醒'}
// var dialog_dict={'voice':'下发语音','text':'下发文字','picture':'下发图片','video_talk':'视频通话'}
// var time_chose_list=['walk_time_set','silence_time_set','time_remind','sleep_time','long_sit_alarm','take_medicine','drink_water']
var sos_detail={};
var time_remind_data={};
var device_set_modal=function(device_id,status){
  // 因为动态加载form，需要主动渲染form，解决select不显示的问题
  document.getElementById("param_set_form").reset();
  // console.log(chosed_dev)
  if(chosed_dev.param_set!=='0'){
    var current_device_set=chosed_dev.param_set
    // console.log(current_device_set)
    // 转换开关参数，使之能适应layui的开关显示
    var on_off_list=['sosmsg_to_phone','low_power_msg','dev_remove_alarm','dev_remove_msg','step_cunt_btn','fall_down']
    for(var k in current_device_set){
      if(current_device_set[k]=='1'){
        current_device_set[k]=true
      }else if(current_device_set[k]=='0'){
        current_device_set[k]=false
      }
    }
    // console.log(current_device_set)
    if(current_device_set.sos!=null){
        sos_detail=current_device_set.sos
        // current_device_set[k]=sos_detail['sos1']+','+sos_detail['sos2']+','+sos_detail['sos3']
      }else{
        sos_detail={}
      }
      if(current_device_set.time_remind!=null){
        time_remind_data=current_device_set.time_remind
        // current_device_set[k]=time_remind_data['clock1']+','+time_remind_data['clock2']+','+time_remind_data['clock3']
      }else{
        time_remind_data={}
      }
    form.val('param_set_form',current_device_set)
    var sos_code=sos_detail['sos1']+','+sos_detail['sos2']+','+sos_detail['sos3']
    if(sos_detail['sos1']==null){
      sos_code='sos'
    }
    $('#sos_set_value').val(sos_code)
    var clock_detail=time_remind_data['clock1']+','+time_remind_data['clock2']+','+time_remind_data['clock3']
    if(time_remind_data['clock1']==null){
      clock_detail=''
    }
    $('#time_remind').val(clock_detail)
  }

  $('#set_device_id').val(device_id)
  // 弹出弹窗
    parent.layer.open({
        type: 1
        ,title:'硬件参数设置: '+device_id
        ,area:'880px'
        ,offset:'60px'  
        ,id: 'command_data' //防止重复弹出
        ,content:$('#param_set_form')
        ,btn: '关闭'
        ,zIndex:999
        // 遮罩把弹窗盖住的问题的解决办法，把遮罩和弹窗放在同一层
        // ,success:function(layero){
        //   console.log(layero)
        //      var mask = $(".layui-layer-shade");
        //      mask.appendTo(layero.parent());
        //      //其中：layero是弹层的DOM对象
        // }
        ,shade: 0 //不显示遮罩
        ,btn1: function(){
          layer.closeAll();
        }
        
      });

// 监听设备功能开关设置并提交后台
form.on('switch(dev_func_switch)',function(obj){
  // console.log(obj.elem.name,obj.elem.checked,device_id)
  var set_command=obj.elem.name;
  var set_value=obj.elem.checked;
  if(set_value==true){
    set_value='1'
  }else{
    set_value='0'
  };
  device_set_ajax(device_id,set_command,set_value);
})
};


// --------sos号码设置start---------//
var sos_set=function(){
  // console.log(sos_detail)
  document.getElementById("sos_set_form").reset();
  // form.render()
  for(var k in sos_detail){
    if(sos_detail[k]=='on'){
      sos_detail[k]=true
    }else if(sos_detail[k]=='0'){
      sos_detail[k]=false
    }
  }
  form.val('sos_set_form',sos_detail)
  layer.open({
    type: 1
    ,title:'设置SOS号码'
    ,area:['500px','340px']
    ,offset:'60px'  
    ,id: 'sos_set_data' 
    ,content:$('#sos_set_form')
    // ,btn: ['提交','关闭']
    ,shade: 0 //不显示遮罩
    // ,btn1: function(){
    //   // $('#submit_btn').click()
      
    // }
    // ,btn2: function(){
    //   layer.closeAll();
    // }
  }); 
}

form.on('submit(sos_set_form)',function(obj){
  // console.log(obj)
  var sos_data=obj.field
  if(sos_data.sos1_sw!='on'){
    sos_data.sos1_sw='0'
  }else{
    if(sos_data.sos1.length!==11){
      layer.msg('sos1-'+sos_data.sos1+'格式不正确')
      return false
    }
  }
  if(sos_data.sos2_sw!='on'){
    sos_data.sos2_sw='0'
  }else{
    if(sos_data.sos2.length!==11){
      layer.msg('sos2-'+sos_data.sos2+'格式不正确')
      return false
    }
  }
  if(sos_data.sos3_sw!='on'){
    sos_data.sos3_sw='0'
  }else{
    if(sos_data.sos3.length!==11){
      layer.msg('sos3-'+sos_data.sos3+'格式不正确')
      return false
    }
  }
  var device_id=$('#set_device_id').val()
  var set_command='sos'
  var set_value=sos_data
  console.log(set_value)
  device_set_ajax(device_id,set_command,set_value)
  return false
})
// --------sos号码设置end---------//

// --------闹钟设置start---------//
var clock_set=function(){
  // console.log(time_remind_data)
  formSelects.render()
  document.getElementById("alarm_clock_form").reset();
  // console.log(time_remind_data)
  for(var k in time_remind_data){
    if(time_remind_data[k]=='1'){
      time_remind_data[k]=true
    }else if(time_remind_data[k]=='0'){
      time_remind_data[k]=false
    }
  }
  // console.log(time_remind_data['customize2'].split(','))
  form.val('alarm_clock_form',time_remind_data)
  formSelects.value('customize1', time_remind_data['customize1'].split(','))
  formSelects.value('customize2', time_remind_data['customize2'].split(','))
  formSelects.value('customize3', time_remind_data['customize3'].split(','))
  layer.open({
    type: 1
    ,title:'闹钟设置'
    ,area:['800px','340px']
    ,offset:'60px'  
    ,id: 'clock_data' 
    ,content:$('#alarm_clock_form')
    ,shade: 0 //不显示遮罩
  }); 
}

form.on('submit(alarm_clock_form)',function(obj){
  // console.log(obj.field)
  var clock_data=obj.field
  if(clock_data.clock1_sw!='on'){
    clock_data.clock1_sw='0'
    if(clock_data.clock1===''){
      clock_data.clock1='00:00'
    }
  }else{
    clock_data.clock1_sw='1'
    if(clock_data.clock1===''){
      layer.msg('请选择时间')
      return false
    }
    if(clock_data.clock1_rate=='customize1'){
      if(clock_data.customize1==''){
        layer.msg('请选择自定义时间')
        return false
      }
    }
  }
  if(clock_data.clock2_sw!='on'){
    clock_data.clock2_sw='0'
    if(clock_data.clock2===''){
      clock_data.clock2='00:00'
    }
  }else{
    clock_data.clock2_sw='1'
    if(clock_data.clock2===''){
      layer.msg('请选择时间')
      return false
    }
    if(clock_data.clock2_rate=='customize2'){
      if(clock_data.customize2==''){
        layer.msg('请选择自定义时间')
        return false
      }
    }
  }
  if(clock_data.clock3_sw!='on'){
    clock_data.clock3_sw='0'
    if(clock_data.clock3===''){
      clock_data.clock3='00:00'
    }
  }else{
    clock_data.clock3_sw='1'
    if(clock_data.clock3===''){
      layer.msg('请选择时间')
      return false
    }
    if(clock_data.clock3_rate=='customize3'){
      if(clock_data.customize3==''){
        layer.msg('请选择自定义时间')
        return false
      }
    }
  }
  var device_id=$('#set_device_id').val()
  var set_command='time_remind'
  var set_value=clock_data
  // console.log(set_value)
  device_set_ajax(device_id,set_command,set_value)
  return false
})
// --------闹钟设置end---------//


// 监听用户输入设备设置参数并提交后台
var device_set=function(set_command,device_id,set_value){
  device_set_ajax(device_id,set_command,set_value)
  return false
}
//命令下发到后台进行处理
var device_set_ajax=function(device_id,set_command,set_value){
  if(chosed_dev.on_off_line!=='online'){
    layer.msg('设备离线，无法执行该指令')
    return false
  }
  console.log(chosed_dev)
  if(set_command=='walk_time_set' | set_command=='sleep_time'){
    set_value=set_value.replace(' ','')
    set_value=set_value.replace(' ','')
    if(set_command=='walk_time_set'){
      set_value=set_value+','+set_value+','+set_value
    }
  }
  var send_time=$('#get_current_time').text()
  var param_data={'device_id':device_id,'set_command':set_command,'set_value':set_value,'send_time':send_time,'port':chosed_dev.dynamic.receive_port}
  param_data=JSON.stringify(param_data)
  console.log(param_data)
  $.ajax({
    type: 'POST',
    data:{param_data},
    url:"/dynamic/?what="+'device_set',
    async:true,
    dataType: 'json',
    success: function(data) {
      if(data=='set_param,ok!'){
        layer.msg('操作成功')
      }else{
         layer.msg(data)
      }
      // console.log(data)
    },
    error:function(obj){
      layer.msg('操作失败')
      console.log(obj)
    }
  });

}
//时间范围
laydate.render({
  elem: '#walk_time_set'
  ,type: 'time'
  ,range: true
  ,format: 'HH:mm'
});

laydate.render({
  elem: '#silence_time_set'
  ,type: 'time'
  ,range: true
});

laydate.render({
  elem: '#sleep_time'
  ,type: 'time'
  ,range: true
  ,format: 'HH:mm'
});
laydate.render({
  elem: '#clock1'
  ,type: 'time'
  ,format: 'HH:mm'
});
laydate.render({
  elem: '#clock2'
  ,type: 'time'
  ,format: 'HH:mm'
});
laydate.render({
  elem: '#clock3'
  ,type: 'time'
  ,format: 'HH:mm'
});
// 设备参数设置功能js部分结束


</script>